package test05;

// 1. 抽象组件接口 - 直播流
interface LiveStream {
    void startLive();
    void endLive();
    String applyEffect();
}

// 2. 具体组件 - 基础直播
class BasicLiveStream implements LiveStream {
    private String streamerName;

    public BasicLiveStream(String streamerName) {
        this.streamerName = streamerName;
    }

    @Override
    public void startLive() {
        System.out.println(streamerName + " 开始基础直播");
    }

    @Override
    public void endLive() {
        System.out.println(streamerName + " 结束直播");
    }

    @Override
    public String applyEffect() {
        return "基础直播画面";
    }
}

// 3. 抽象装饰器 - 特效装饰器
abstract class EffectDecorator implements LiveStream {
    protected LiveStream decoratedStream;

    public EffectDecorator(LiveStream stream) {
        this.decoratedStream = stream;
    }

    @Override
    public void startLive() {
        decoratedStream.startLive();
    }

    @Override
    public void endLive() {
        decoratedStream.endLive();
    }

    @Override
    public String applyEffect() {
        return decoratedStream.applyEffect();
    }
}

// 4. 具体装饰器 - 美颜特效
class BeautyEffect extends EffectDecorator {
    private String beautyType;

    public BeautyEffect(LiveStream stream, String beautyType) {
        super(stream);
        this.beautyType = beautyType;
    }

    @Override
    public void startLive() {
        super.startLive();
        System.out.println("启用美颜特效: " + beautyType);
    }

    @Override
    public String applyEffect() {
        return super.applyEffect() + " + " + beautyType + "美颜";
    }
}

// 5. 具体装饰器 - 滤镜特效
class FilterEffect extends EffectDecorator {
    private String filterType;

    public FilterEffect(LiveStream stream, String filterType) {
        super(stream);
        this.filterType = filterType;
    }

    @Override
    public void startLive() {
        super.startLive();
        System.out.println("启用滤镜特效: " + filterType);
    }

    @Override
    public String applyEffect() {
        return super.applyEffect() + " + " + filterType + "滤镜";
    }
}

// 6. 具体装饰器 - 贴纸特效
class StickerEffect extends EffectDecorator {
    private String stickerType;

    public StickerEffect(LiveStream stream, String stickerType) {
        super(stream);
        this.stickerType = stickerType;
    }

    @Override
    public void startLive() {
        super.startLive();
        System.out.println("启用贴纸特效: " + stickerType);
    }

    @Override
    public String applyEffect() {
        return super.applyEffect() + " + " + stickerType + "贴纸";
    }
}

// 7. 客户端测试类
public class DouyinLiveSystem {
    public static void main(String[] args) {
        System.out.println("=== 抖音直播特效系统 ===\n");

        // 测试1: 基础直播
        System.out.println("--- 测试1: 基础直播 ---");
        LiveStream basicLive = new BasicLiveStream("主播小明");
        basicLive.startLive();
        System.out.println("当前效果: " + basicLive.applyEffect());
        basicLive.endLive();

        // 测试2: 单一特效
        System.out.println("\n--- 测试2: 美颜特效直播 ---");
        LiveStream beautyLive = new BeautyEffect(
                new BasicLiveStream("主播小红"), "平滑皮肤+大眼瘦脸");
        beautyLive.startLive();
        System.out.println("当前效果: " + beautyLive.applyEffect());
        beautyLive.endLive();

        // 测试3: 多种特效组合
        System.out.println("\n--- 测试3: 全特效直播 ---");
        LiveStream fullEffectLive = new BeautyEffect(
                new FilterEffect(
                        new StickerEffect(
                                new BasicLiveStream("主播小刚"), "猫耳朵"
                        ), "日系"
                ), "大眼瘦脸"
        );
        fullEffectLive.startLive();
        System.out.println("当前效果: " + fullEffectLive.applyEffect());
        fullEffectLive.endLive();

        // 测试4: 不同顺序组合（效果相同）
        System.out.println("\n--- 测试4: 不同顺序特效组合 ---");
        LiveStream order1 = new BeautyEffect(
                new FilterEffect(
                        new StickerEffect(
                                new BasicLiveStream("主播A"), "趣味边框"
                        ), "自然"
                ), "平滑皮肤"
        );

        LiveStream order2 = new StickerEffect(
                new BeautyEffect(
                        new FilterEffect(
                                new BasicLiveStream("主播A"), "自然"
                        ), "平滑皮肤"
                ), "趣味边框"
        );

        System.out.println("顺序1效果: " + order1.applyEffect());
        System.out.println("顺序2效果: " + order2.applyEffect());
        System.out.println("效果是否相同: " +
                order1.applyEffect().equals(order2.applyEffect()));

        // 测试5: 动态添加特效
        System.out.println("\n--- 测试5: 直播中动态添加特效 ---");
        LiveStream dynamicLive = new BasicLiveStream("主播小美");
        dynamicLive.startLive();
        System.out.println("初始效果: " + dynamicLive.applyEffect());

        // 直播过程中添加美颜
        dynamicLive = new BeautyEffect(dynamicLive, "平滑皮肤");
        System.out.println("添加美颜后: " + dynamicLive.applyEffect());

        // 直播过程中添加滤镜
        dynamicLive = new FilterEffect(dynamicLive, "黑白");
        System.out.println("添加滤镜后: " + dynamicLive.applyEffect());

        // 直播过程中添加贴纸
        dynamicLive = new StickerEffect(dynamicLive, "趣味边框");
        System.out.println("添加贴纸后: " + dynamicLive.applyEffect());

        dynamicLive.endLive();
    }
}